package id.apps.surabayacityguide;

import com.actionbarsherlock.view.Menu;
import com.github.rtyley.android.sherlock.roboguice.activity.RoboSherlockActivity;

import roboguice.inject.InjectView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

/*
 * Class Menu Utama
 * extends class RoboSherlockActivity
 */
public class MainActivity extends RoboSherlockActivity implements OnItemClickListener
{
	// Deklarasi widget
	private @InjectView(R.id.lv_menuutama)
	ListView					lvMenuUtama;

	// variable global
	private String[]			list_item		=
												{
			"Ensiklopedia", "Referensi Lokasi", "Event Kota", "Cerita Legenda"
												};

	private static final int	ID_ENSIKLOPEDI	= 0;
	private static final int	ID_LOKASI		= 1;
	private static final int	ID_EVENT		= 2;
	private static final int	ID_CERITA		= 3;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		lvMenuUtama.setOnItemClickListener(this);
		setItemToListview();
	}

	/*
	 * set adapter untuk listview
	 */
	private void setItemToListview()
	{
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list_item);
		lvMenuUtama.setAdapter(adapter);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// TODO Auto-generated method stub
		return super.onCreateOptionsMenu(menu);
	}

	/*
	 * event handling ketika listview di click (non-Javadoc)
	 * 
	 * @see
	 * android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget
	 * .AdapterView, android.view.View, int, long)
	 */
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id)
	{
		switch (position)
		{
			case ID_ENSIKLOPEDI:
				Toast.makeText(this, "ensikopedi", Toast.LENGTH_SHORT).show();
				break;
			case ID_LOKASI:
				startActivity(new Intent(this, ReferensiLokasiActivity.class));
				break;
			case ID_EVENT:
				Toast.makeText(this, "event", Toast.LENGTH_SHORT).show();
				break;
			case ID_CERITA:
				startActivity(new Intent(this, CeritaLegendaActivity.class));
				break;
		}
	}
}
